
<%
	String sessionMail = (String) session.getAttribute("sessionMail");
	int qId = Integer.parseInt(request.getParameter("qId"));
	String qTitle = request.getParameter("qTitle");
	String qBody = request.getParameter("qBody");
	if (sessionMail == null) {
%>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<body onload="load()">
	<%
		}
	%>
	<jsp:include page="header.jsp" />
	<div id="page-wrapper">
		<input type="hidden" value="<%=qId%>" id="qId" />
		<div class="col-sm-10 col-sm-offset-2">
			<div class="row">
				<div class="col-lg-8">
					<div id="question" name="question" class="col-lg-8">
						<h3 class="page-header"><%=qTitle%></h3>
						<div id="questionBody" name="questionBody" class="col-lg-8">
							<%=qBody%></div>
						<br>
					<br>
					
					<form action="/MetaQBank/rest/comment/postQuestionComment?qId=<%=qId %>" method="post">		
				<div class="col-lg-8">
					
							<a class="label label-info" data-toggle="collapse" data-parent="#accordion" href="#<%=qId%>">Comment</a>
							
						</div>
						 <div class="col-lg-8">
						 
							<div class="panel-group" id="accordion">
								<div class="panel panel-default">
									
									<div id="<%=qId %>" class="panel-collapse collapse">
										<h4 class="panel-title">
											Your Comment
										</h4>
										<div class="panel-body">
											 <textarea class="textarea form-control" name ="commentBody" placeholder="Enter comment" ></textarea>
											 <div class="col-lg-8">
												<button type="submit" class="btn btn-primary" id="save" name="save" ng-click="getAnswerOnComment()">Submit</button><span></span>
												<a  class="btn btn-primary" href="postAnswer.jsp?qId=<%=qId%> "id="cancel" name="cancel">Cancel</a>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					
				</form>
			
					<div class="row"></div>
					
						<div ng-app="">
							<h3 class="page-header">
								Answers<label id="answerLength"></label>
							</h3>

							<div ng-controller="getAnswerController">


								<div ng-repeat="ansList in ansList">

									<div class="col-lg-8">
										<div class="panel panel-default">

											<div class="panel-body">{{ansList.aBody}} </div>
										</div>
									</div>
									
											
				<div class="col-lg-8">
								
							<a class="label label-info" data-toggle="collapse" data-parent="#accordion1" href="#a{{ansList.aId}}">{{ansList.aId}} Comment</a>
							
						</div>
						 <div class="col-lg-8">
						 
							<div class="panel-group" id="accordion1">
								<div class="panel panel-default">
									
									<div id="a{{ansList.aId}}" class="panel-collapse collapse">
										<h4 class="panel-title">
											Your Comment
										</h4>
										<div class="panel-body">
											<input type="hidden" value="{{ansList.aId}}" id="aId"/>
											 <textarea class="textarea form-control" name ="commentBody" id="commentBody" placeholder="Enter comment" ></textarea>
											 <div class="col-lg-8">
												<button type="submit" class="btn btn-primary" id="answerComment" name="save" onClick="postComment()" >Submit</button><span></span>
												<a  class="btn btn-primary" href="postAnswer.jsp?qId=<%=qId%> "id="cancel" name="cancel">Cancel</a>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					
				
								</div>

								<div class="col-lg-8">

									<div>
										<h4 class="page-header">Post Your Answer here</h4>
										
											<input type="input" style="display: none" name="qTitle"
												id="qTitle" value="{{ansList.Title}}">
											<textarea class="textarea form-control" name="aBody"
												id="aBody" placeholder="Enter text ..."
												style=" resize: none;"></textarea>
											<br />
											<div class="col-lg-8">
												<div class="col-lg-8">
													<button type="submit" class="btn btn-primary"
														id="postAnswer" name="answer" ng-click="getAnswerOnPost()">Post
														Your Answer</button>
													<span></span>
												</div>
											</div>
										
									</div>
								</div>

							</div>
						</div>

					</div>

				</div>




				<!----/.col--->
				<div class="col-lg-4">
					<h3 class="page-header">Expertise</h3>
					<div class="row">
						<div class="col-lg-4">
							<img src="images/images.jpg" class="image-rounded"
								alt="userImage"
								style="width: 50px; height: 50px; border: solid;"> <br>
						</div>
						<div class="col-lg-8">
							<label>Username</label><br> <label>Points</label><br> <label>Answers</label><br>
							<label>Questions</label>
						</div>
					</div>
				</div>
				<div class="col-lg-4">
					<h3 class="page-header">Personal Info</h3>
					<ul style="list-style: none;">
						<li>Fullname</li>
						<li>Email</li>
					</ul>
				</div>
			</div>
			<!----/.col--->
		</div>
		<!-- /.row 2-->
	</div>


	<script>
		
	</script>

	<script>
	
	function postComment() {    
		alert("ajax");
	
		window.location.replace("/MetaQBank/rest/comment/postAnswerComment?aId="+document.getElementById('aId').value+"&body="+document.getElementById('commentBody').value);
		
		}
	
		function getAnswerController($scope, $http) {
			var qId = document.getElementById('qId').value;

			$http
					.get(
							"http://localhost:8080/MetaQBank/rest/answer/getAnswers?qId="
									+ qId)
					.success(
							function(response) {

								$scope.ansList = response;

								document.getElementById('answerLength').textContent = "("
										+ response.length + ")";

							});

			$scope.getAnswerOnPost = function() {

				alert("hh");
				
				$http
				.get(
						"http://localhost:8080/MetaQBank/rest/answer/postAnswers?qId="
								+ qId+"&aBody="+document.getElementById('aBody').value)
				.success(
						function(response) {
					alert("hhh"+document.getElementById('aBody').value);
							$scope.ansList = response;

							document.getElementById('answerLength').textContent = "("
									+ response.length + ")";

						});
			}
			
			
			
			

		}
	</script>